package wb.is.besti.edu.cd.emergency_responsesys.widget;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import wb.is.besti.edu.cd.emergency_responsesys.R;
import wb.is.besti.edu.cd.emergency_responsesys.utils.Options;

public class OptionsAdapter extends ArrayAdapter {
    private int resourceId;//Item布局文件ID
    private View view;
    private ViewHolder holder;
    private Options options;


    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        options = (Options)getItem(position);

        if (convertView==null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,parent,false);

            holder = new ViewHolder();
            holder.optionsImage = (ImageView)view.findViewById(R.id.iv_itemImage);
            holder.optionsText = (TextView)view.findViewById(R.id.tv_itemText);
            holder.tv_content = (TextView)view.findViewById(R.id.tv_content);
            holder.tv_time=(TextView)view.findViewById(R.id.tv_time);
            view.setTag(holder);
        }else {
            view = convertView;
            holder=(ViewHolder)view.getTag();
        }
        holder.optionsImage.setImageResource(options.getOptionsImage());
        holder.optionsText.setText(options.getOptionsText());
        holder.tv_content.setText(options.getContent());
        holder.tv_time.setText(options.getTime());
        return view;
    }

    public OptionsAdapter(@NonNull Context context, int resource, @NonNull List objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    class ViewHolder{
        ImageView optionsImage;
        TextView optionsText,tv_content,tv_time;
    }
}
